package test;

import java.io.*;

class Test {
    static int c_used[][] = new int[0][];
    
    public static int find(int c[]) {
	for(int i=0;i<c_used.length;i++) {
	    boolean found = true;
	    for(int j=0;j<c_used[i].length;j++) {
		if (c[j] != c_used[i][j]) {
		    found = false;
		    break;
		}
	    }
	    if (found) return i;
	}
	return -1;
    }
    
    public static void add(int c[]) {
	int new_c_used[][] = new int[c_used.length+1][];
	for(int i=0;i<c_used.length;i++) {
	    new_c_used[i] = c_used[i];
	}
	new_c_used[c_used.length] = c;
	c_used = new_c_used;
    }

    public static void main(String args[]) throws IOException {
	BufferedReader in = new BufferedReader(new FileReader(args[0]));
	
	int nodes = Integer.parseInt(in.readLine());
	int x[][] = new int[nodes][nodes];
	for(int i=0;i<nodes;i++) {
	    String strs[] = in.readLine().split(" ");
	    for(int j=0;j<nodes;j++) {
		x[i][j] = Integer.parseInt(strs[j]);
	    }	    
	}

	for(int i=0;i<nodes;i++) {
	    for(int j=0;j<nodes;j++) {
		System.out.print(" " + x[i][j]);
	    }
	    System.out.println();
	}
	System.out.println();
	
	System.out.println("--- ORIGINAL SOLUTION ---");
	System.out.println();

	for(int i=0;i<nodes;i++) {
	    System.out.println("trigger_"+i+"_action() {");
	    System.out.println("  execute_trigger_"+i+"_action();");
	    for(int j=0;j<nodes;j++) {
		if (x[i][j] == 1) {
		    System.out.println("  if (trigger_"+
				       j+"_condition()) trigger_" +
				       j+"_action();");
		}
	    }	    
	    System.out.println("}");
	    System.out.println("");
	}	

	System.out.println("--- NEW SOLUTION ---");
	System.out.println();
	
	for(int i=0;i<nodes;i++) {
	    if (find(x[i]) == -1) add(x[i]);
	}

	for(int xi=0;xi<c_used.length;xi++) {
	    int current[] = c_used[xi];
	    System.out.println("f"+xi+"() {");
	    for(int i=0; i<nodes; i++) {
		if (current[i] == 1) {
		    System.out.print("  if (trig" + i + ".cond()) { ");
		    System.out.print("trig" + i+ ".act(); ");
		    int temp[] = new int[nodes];
		    for(int j=0;j<nodes;j++) {
			temp[j] = x[i][j];
		    }
		    
		    for(int j=i+1;j<nodes;j++) {
			if (current[j] == 1) {
			    temp[j] = 1;
			}
		    }
		      
		    if (find(temp) == -1) add(temp);		    
		    System.out.println("f" + find(temp) + "(); return; }");
		}
	    }
	    System.out.println("}");
	    System.out.println();
	}
    }
}
